/*
 * MockUserImpl.java   ver    30/ott/2009
 * 
 * Copyright (c) 2009 mentalsmash.org
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * The use of the Apache License does not indicate that this project is
 * affiliated with the Apache Software Foundation.
 */
package org.mentalsmash.tazio.transactions.mock;

/**
 * @author Andrea Reale
 * @version 0.0.1
 */
public class MockUserImpl implements User {

    private static final long serialVersionUID = -8547735641575081693L;

    private String username;
    private final int age;
    private User bestFriend;

    public MockUserImpl( ) {
	username = "default";
	age =25;
    }
    
    public MockUserImpl(final String username, final int age,
	    final User bestFriend) {
	this.username = username;
	this.age = age;
	this.bestFriend = bestFriend;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.mentalsmash.tazio.transactions.mock.MockUser#bestFriend()
     */
    @Override
    public User bestFriend() {
	return this.bestFriend;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.mentalsmash.tazio.transactions.mock.MockUser#getAge()
     */
    @Override
    public int getAge() {
	return this.age;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.mentalsmash.tazio.transactions.mock.MockUser#getUsername()
     */
    @Override
    public String getUsername() {
	return this.username;
    }

    /*
     * (non-Javadoc)
     * 
     * @seeorg.mentalsmash.tazio.transactions.mock.MockUser#setBestFriend(org.
     * mentalsmash.tazio.transactions.mock.MockUser)
     */
    @Override
    public void setBestFriend(final User friend) {
	this.bestFriend = friend;

    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * org.mentalsmash.tazio.transactions.mock.MockUser#setUsername(java.lang
     * .String)
     */
    @Override
    public void setUsername(final String username) {
	this.username = username;

    }

    @Override
    public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result + this.age;
	result = prime * result
		+ ((this.bestFriend == null) ? 0 : this.bestFriend.hashCode());
	result = prime * result
		+ ((this.username == null) ? 0 : this.username.hashCode());
	return result;
    }

    @Override
    public boolean equals(final Object obj) {
	if (this == obj) {
	    return true;
	}
	if (obj == null) {
	    return false;
	}
	if (getClass() != obj.getClass()) {
	    return false;
	}
	final MockUserImpl other = (MockUserImpl) obj;
	if (this.age != other.age) {
	    return false;
	}
	if (this.bestFriend == null) {
	    if (other.bestFriend != null) {
		return false;
	    }
	} else if (!this.bestFriend.equals(other.bestFriend)) {
	    return false;
	}
	if (this.username == null) {
	    if (other.username != null) {
		return false;
	    }
	} else if (!this.username.equals(other.username)) {
	    return false;
	}
	return true;
    }

}
